<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><title>Python: module sa</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head><body bgcolor="#f0f0f8">

<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading">
<tr bgcolor="#7799ee">
<td valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial">&nbsp;<br><big><big><strong>sa</strong></big></big></font></td
><td align=right valign=bottom
><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/home/jgenson/Development/betelgeuse-ml/lib/ml/sa.py">/home/jgenson/Development/betelgeuse-ml/lib/ml/sa.py</a></font></td></tr></table>
    <p><tt>A&nbsp;general&nbsp;implementation&nbsp;of&nbsp;simulated&nbsp;annealing&nbsp;(sa).<br>
&nbsp;<br>
Simulated&nbsp;annealing&nbsp;has&nbsp;its&nbsp;roots&nbsp;in&nbsp;metallurgy,&nbsp;where&nbsp;materials&nbsp;are&nbsp;heated<br>
and&nbsp;then&nbsp;cooled&nbsp;to&nbsp;alter&nbsp;their&nbsp;physical&nbsp;properties.&nbsp;Simulated&nbsp;annealing<br>
similarly&nbsp;keeps&nbsp;track&nbsp;of&nbsp;the&nbsp;system's&nbsp;"temperature",&nbsp;and&nbsp;accepts&nbsp;solutions<br>
with&nbsp;greater&nbsp;randomness&nbsp;when&nbsp;the&nbsp;temperature&nbsp;is&nbsp;high.&nbsp;This&nbsp;helps&nbsp;the<br>
algorithm&nbsp;resist&nbsp;becoming&nbsp;stuck&nbsp;in&nbsp;local&nbsp;optima&nbsp;early&nbsp;on.&nbsp;As&nbsp;the&nbsp;system<br>
cools,&nbsp;its&nbsp;propensity&nbsp;for&nbsp;randomness&nbsp;decreases,&nbsp;and&nbsp;it&nbsp;essentially&nbsp;becomes&nbsp;a<br>
basic&nbsp;hill&nbsp;climber.<br>
&nbsp;<br>
Most&nbsp;functions&nbsp;in&nbsp;this&nbsp;module&nbsp;are&nbsp;higher-order&nbsp;functions&nbsp;that&nbsp;return&nbsp;another<br>
function.&nbsp;To&nbsp;create&nbsp;an&nbsp;SA&nbsp;optimizer,&nbsp;you&nbsp;must&nbsp;minimally&nbsp;call&nbsp;create_optimizer<br>
with&nbsp;a&nbsp;measure_energy&nbsp;(aka&nbsp;fitness)&nbsp;function,&nbsp;a&nbsp;change_state&nbsp;(aka&nbsp;mutate)<br>
function,&nbsp;and&nbsp;values&nbsp;for&nbsp;the&nbsp;initial&nbsp;temperature&nbsp;and&nbsp;temperature&nbsp;reduction.<br>
&nbsp;<br>
Copyright&nbsp;(C)&nbsp;2013&nbsp;Jerrad&nbsp;Michael&nbsp;Genson<br>
&nbsp;<br>
This&nbsp;program&nbsp;is&nbsp;free&nbsp;software:&nbsp;you&nbsp;can&nbsp;redistribute&nbsp;it&nbsp;and/or&nbsp;modify<br>
it&nbsp;under&nbsp;the&nbsp;terms&nbsp;of&nbsp;the&nbsp;BSD&nbsp;3-Clause&nbsp;License&nbsp;as&nbsp;published&nbsp;by<br>
the&nbsp;Open&nbsp;Source&nbsp;Initiative.<br>
&nbsp;<br>
This&nbsp;program&nbsp;is&nbsp;distributed&nbsp;in&nbsp;the&nbsp;hope&nbsp;that&nbsp;it&nbsp;will&nbsp;be&nbsp;useful,<br>
but&nbsp;WITHOUT&nbsp;ANY&nbsp;WARRANTY;&nbsp;without&nbsp;even&nbsp;the&nbsp;implied&nbsp;warranty&nbsp;of<br>
MERCHANTABILITY&nbsp;or&nbsp;FITNESS&nbsp;FOR&nbsp;A&nbsp;PARTICULAR&nbsp;PURPOSE.&nbsp;&nbsp;See&nbsp;the<br>
BSD&nbsp;3-Clause&nbsp;License&nbsp;for&nbsp;more&nbsp;details.<br>
&nbsp;<br>
You&nbsp;should&nbsp;have&nbsp;received&nbsp;a&nbsp;copy&nbsp;of&nbsp;the&nbsp;BSD&nbsp;3-Clause&nbsp;License<br>
along&nbsp;with&nbsp;this&nbsp;program.&nbsp;&nbsp;If&nbsp;not,&nbsp;see<br>
&lt;https://betelgeuse-ml.googlecode.com/hg/LICENSE&gt;</tt></p>
<p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#aa55cc">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Modules</strong></big></font></td></tr>
    
<tr><td bgcolor="#aa55cc"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%"><table width="100%" summary="list"><tr><td width="25%" valign=top><a href="math.html">math</a><br>
</td><td width="25%" valign=top><a href="random.html">random</a><br>
</td><td width="25%" valign=top></td><td width="25%" valign=top></td></tr></table></td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#eeaa77">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Functions</strong></big></font></td></tr>
    
<tr><td bgcolor="#eeaa77"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%"><dl><dt><a name="-create_optimizer"><strong>create_optimizer</strong></a>(measure_energy, change_state, temperature, reduction, magnitude<font color="#909090">=0.1</font>)</dt><dd><tt>Create&nbsp;an&nbsp;optimizer&nbsp;using&nbsp;simulated&nbsp;annealing.<br>
&nbsp;<br>
Args:<br>
&nbsp;&nbsp;&nbsp;&nbsp;measure_energy:&nbsp;A&nbsp;function&nbsp;that&nbsp;takes&nbsp;a&nbsp;system&nbsp;state&nbsp;as&nbsp;input&nbsp;and<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;returns&nbsp;its&nbsp;energy&nbsp;level&nbsp;as&nbsp;a&nbsp;value&nbsp;between&nbsp;0&nbsp;and<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1,&nbsp;where&nbsp;lower&nbsp;energies&nbsp;are&nbsp;better.<br>
&nbsp;&nbsp;&nbsp;&nbsp;change_state:&nbsp;A&nbsp;function&nbsp;that&nbsp;randomly&nbsp;changes&nbsp;the&nbsp;state&nbsp;of&nbsp;a&nbsp;given<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;system.&nbsp;It&nbsp;takes&nbsp;a&nbsp;system&nbsp;state&nbsp;as&nbsp;input,&nbsp;along&nbsp;with<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;the&nbsp;magnitude&nbsp;of&nbsp;the&nbsp;change,&nbsp;and&nbsp;returns&nbsp;a&nbsp;new&nbsp;state.<br>
&nbsp;&nbsp;&nbsp;&nbsp;temperature:&nbsp;The&nbsp;temperature&nbsp;to&nbsp;start&nbsp;the&nbsp;annealing&nbsp;schedule&nbsp;at.<br>
&nbsp;&nbsp;&nbsp;&nbsp;reduction:&nbsp;A&nbsp;real&nbsp;value&nbsp;between&nbsp;0&nbsp;and&nbsp;1&nbsp;to&nbsp;reduce&nbsp;temperature&nbsp;by<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;after&nbsp;each&nbsp;cycle&nbsp;of&nbsp;annealing.<br>
&nbsp;<br>
Keywords:<br>
&nbsp;&nbsp;&nbsp;&nbsp;magnitude:&nbsp;Magnitude&nbsp;of&nbsp;each&nbsp;state&nbsp;change&nbsp;as&nbsp;a&nbsp;real&nbsp;value&nbsp;between<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;and&nbsp;1.<br>
&nbsp;<br>
Returns:<br>
&nbsp;&nbsp;&nbsp;&nbsp;An&nbsp;optimizer&nbsp;function&nbsp;that&nbsp;uses&nbsp;simulated&nbsp;annealing.&nbsp;This&nbsp;function&nbsp;is<br>
&nbsp;&nbsp;&nbsp;&nbsp;not&nbsp;reusable,&nbsp;since&nbsp;it&nbsp;must&nbsp;preserve&nbsp;the&nbsp;state&nbsp;of&nbsp;the&nbsp;annealing<br>
&nbsp;&nbsp;&nbsp;&nbsp;schedule.</tt></dd></dl>
</td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#55aa55">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Data</strong></big></font></td></tr>
    
<tr><td bgcolor="#55aa55"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%"><strong>__contact__</strong> = 'jerradgenson@gmail.com'<br>
<strong>__copyright__</strong> = 'Copyright 2013 Jerrad Michael Genson'<br>
<strong>__license__</strong> = 'BSD 3-Clause'</td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#7799ee">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Author</strong></big></font></td></tr>
    
<tr><td bgcolor="#7799ee"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%">Jerrad&nbsp;Genson</td></tr></table>
</body></html>